package com.tedu.pj.common.handler;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *
 * </p>
 *
 * @author Song
 * @since 2020/10/17
 */
@Component
//@Aspect
@Slf4j
public class MethodHandler {

    @Pointcut("execution(public * com.tedu.pj.sys.controller.*.*(..))")
    public void pointCut(){}

    @Around("pointCut()")
    public Object aroud(ProceedingJoinPoint joinPoint) throws Throwable {
        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = ((ServletRequestAttributes)requestAttributes).getRequest();
        log.info("Method {}",request.getMethod());
        Object proceed = joinPoint.proceed();
        return proceed;
    }

    @AfterThrowing(value = "pointCut()")
    public void throwing (){
        System.out.println("s");
    }

    @AfterReturning("pointCut()")
    public void rut(){

    }

    @Before("pointCut()")
    public void before(){

    }

    @After("pointCut()")
    public void after(){

    }
}
